﻿using System;
using System.Collections.Generic;
using System.Text;
using MCMLXVII.BackEnd.Services.Common.Messages;
using MCMLXVII.BackEnd.Services.OrganizationChart.BusinessActions;
using MCMLXVII.BackEnd.Services.OrganizationChart.Messages;
using MCMLXVII.BackEnd.Services.Core.BusinessActions;
using MCMLXVII.BackEnd.Services.SystemConfiguration.Messages;
using MCMLXVII.BackEnd.Services.SessionManagement.Messages;
using MCMLXVII.BackEnd.Services.SessionManagement.BusinessActions;
using MCMLXVII.Core.Common.BackEnd;
using MCMLXVII.BackEnd.Data.SystemDatabase;
using MCMLXVII.BackEnd.Data.OrganizationChart;
using MCMLXVII.BackEnd.Common;
using MCMLXVII.Backend.Services.WCF;
using MCMLXVII.Core.Common;

namespace MCMLXVII.BackEnd.Services.WCFService
{
    public class BusinessActions:IBusinessActions
    {

        public BusinessActions()
        {
        }

        #region IBusinessActions Members

        public msgNewSessionResponse GetNewSession(msgNewSessionRequest req)
        {
            try
            {
                msgNewSessionResponse resp = NewSession.GetNewSession(req);
                return resp;
            }
            catch (Exception e)
            {
                //TO DO
                Console.WriteLine(e.Message);
                throw e;
            }
        }

        public msgOrganizationNodeInfo GetOrganizationTree(msgVoidRequest req)
        {
            return OrganizationTree.GetOrganizationTree(req);
        }

        public msgOrganizationNodeInfo GetOrganizationDestinationTree(msgSimpleNodeRequest req)
        {
            return OrganizationTree.GetOrganizationDestinationTree(req);
        }
        
        [NodeAccessAuthorizationBehaviour("R")]
        public msgGenericItemList<msgOrganizationTreeNodeMember> GetOrganizationTreeNodeMembers(msgSimpleNodeRequest req)
        {
            return new msgGenericItemList<msgOrganizationTreeNodeMember>(OrganizationMembers.GetOrganizationTreeNodeMembers(req));
        }

        [NodeAccessAuthorizationBehaviour("U")]
        public msgGenericItemResponse<int> UpdateOrganizationTreeNode(msgUpdateOrganizationTreeNode req)
        {
                return new msgGenericItemResponse<int>(OrganizationTree.UpdateOrganizationTreeNode(req));
        }

        [NodeAccessAuthorizationBehaviour("U")]
        public msgGenericItemResponse<int> MoveOrganizationTreeNode(msgMoveNodeRequest req)
        {
                return new msgGenericItemResponse<int>(OrganizationTree.MoveOrganizationTreeNode(req));
        }

        [NodeAccessAuthorizationBehaviour("U")]
        public msgGenericItemResponse<int> MoveOrganizationMember(msgMoveMemberRequest req)
        {
                return new msgGenericItemResponse<int>(OrganizationMembers.MoveOrganizationMember(req));
        }

        [NodeAccessAuthorizationBehaviour("U")]
        public msgGenericItemResponse<int> UpdateOrganizationMember(msgUpdateOrganizationMember req)
        {
                return new msgGenericItemResponse<int>(OrganizationMembers.UpdateOrganizationMember(req));
        }

        [NodeAccessAuthorizationBehaviour("D")]
        public msgGenericItemResponse<bool> DeleteOrganizationTreeNode(msgSimpleNodeRequest req)
        {
                return new msgGenericItemResponse<bool>(OrganizationTree.DeleteOrganizationTreeNode(req));
        }

        [NodeAccessAuthorizationBehaviour("D")]
        public msgGenericItemResponse<bool> DeleteOrganizationMember(msgSimpleMemberRequest req)
        {
                return new msgGenericItemResponse<bool>(OrganizationMembers.DeleteOrganizationMember(req));
        }

        [NodeAccessAuthorizationBehaviour("R")]
        public msgOrganizationMemberInfo GetOrganizationMemberInfo(msgSimpleMemberRequest req)
        {
                return OrganizationMembers.GetOrganizationMemberInfo(req);
        }

        [NodeAccessAuthorizationBehaviour("R")]
        public msgGenericItemList<string> GetOrganizationTreeNodeEfectiveRights(msgSimpleNodeRequest req)
        {
                return new msgGenericItemList<string>(OrganizationTree.GetOrganizationTreeNodeEfectiveRights(req));
        }

        [NodeAccessAuthorizationBehaviour("A")]
        public msgGenericItemList<msgOrganizationNodeAuditInfo> GetOrganizationTreeNodeAudit(msgSimpleNodeRequest req)
        {
                return new msgGenericItemList<msgOrganizationNodeAuditInfo>(OrganizationTree.GetOrganizationTreeNodeAudit(req));
        }

        [NodeAccessAuthorizationBehaviour("A")]
        public msgGenericItemList<msgOrganizationMemberAuditInfo> GetOrganizationMemberAudit(msgSimpleMemberRequest req)
        {
                return new msgGenericItemList<msgOrganizationMemberAuditInfo>(OrganizationMembers.GetOrganizationMemberAudit(req));
        }

        public msgXMLResponse GetDirectoryTree(msgGenericItemRequest<int> req)
        {
            return DirectoryServices.GetDirectoryTree(req);
        }


        public msgXMLResponse GetDirectoryNodeUsers(msgSecurityUsersListRequest req)
        {
            return DirectoryServices.GetDirectoryNodeUsers(req);
        }

        public msgXMLResponse GetDirectoryNodeGroups(msgSecurityUsersListRequest req)
        {
            return DirectoryServices.GetDirectoryNodeGroups(req);
        }

        public msgGenericItemList<msgMembershipInfo> GetOrganizationTreeMembers(msgFindMembersRequest req)
        {
            return new msgGenericItemList<msgMembershipInfo>(OrganizationLists.GetOrganizationTreeMembers(req));
        }

        public msgGenericItemList<msgMembershipInfo> GetOrganizationTreeRoleMembers(msgFindMembersRequest req)
        {
            return new msgGenericItemList<msgMembershipInfo>(OrganizationLists.GetOrganizationTreeRoleMembers(req));
        }

        public msgMembershipInfo GetOrganizationTreeMemberDesc(msgGenericItemRequest<int> req)
        {
            return OrganizationLists.GetOrganizationTreeMemberDesc(req);
        }

        public msgLanguajesListResponse GetContentLanguagesList(msgGenericItemRequest<bool> req)
        {
            return MultilingualContents.GetContentLanguagesList(req);
        }

        public msgGenericItemResponse<string> GetDefaultLanguage(msgVoidRequest req)
        {
            return new msgGenericItemResponse<string>(MultilingualContents.GetDefaultLanguage(req));
        }

        public msgNewOrganizationTreeItemResponse CreateNewOrganizationTreeNode(msgNewOrganizationTreeNode req)
        {
            return OrganizationTree.CreateNewOrganizationTreeNode(req);
        }
        
        [NodeAccessAuthorizationBehaviour("C")]
        public msgNewOrganizationTreeItemResponse CreateNewOrganizationMember(msgNewOrganizationMember req)
        {
                return OrganizationMembers.CreateNewOrganizationMember(req);
        }

        public msgGenericItemList<msgOrganizationTreeMembersClass> GetOrganizationTreeMembersClasses(msgVoidRequest req)
        {
            return new msgGenericItemList<msgOrganizationTreeMembersClass>(OrganizationMembers.GetOrganizationTreeMembersClasses(req));
        }

        public msgGenericItemList<msgBasicOrganizationMemberInfo> FindorganizationMembersByDescription(msgGenericItemRequest<string> req)
        {
            return new msgGenericItemList<msgBasicOrganizationMemberInfo>(OrganizationMembers.FindOrganizationMembersByDescription(req));
        }

        [NodeAccessAuthorizationBehaviour("S")]
        public msgOrganizationTreeNodeSecurity GetOrganizationTreeNodeSecurity(msgSimpleNodeRequest req)
        {
                return OrganizationTree.GetOrganizationTreeNodeSecurity(req);
        }

        [NodeAccessAuthorizationBehaviour("S")]
        public msgGenericItemResponse<int> UpdateOrganizationTreeNodeSecurity(msgUpdateOrganizationTreeNodeSecurity req)
        {
                return new msgGenericItemResponse<int>(OrganizationTree.UpdateOrganizationTreeNodeSecurity(req));
        }

        public msgGenericItemList<msgSecurityProvider> GetEnabledSecurityProviders(msgVoidRequest req)
        {
            return new msgGenericItemList<msgSecurityProvider>(DirectoryServices.GetEnabledSecurityProviders(req));
        }


        public msgGenericItemList<msgToolsInfo> GetToolsList(msgVoidRequest req)
        {
            return new msgGenericItemList<msgToolsInfo>(Tools.GetToolsList(req));
        }

        public msgToolsInfo GetToolInfo(msgGenericItemRequest<string> req)
        {
            return Tools.GetToolInfo(req);
        }

        public msgGenericItemList<msgPermissionInfo> GetPermissionsList(msgVoidRequest req)
        {
            return new msgGenericItemList<msgPermissionInfo>(Tools.GetPermissionsList(req));
        }

        public msgGenericItemList<msgPermissionInfo> GetMemberPermissionsList(msgGenericItemRequest<int> req)
        {
            return new msgGenericItemList<msgPermissionInfo>(Tools.GetMemberPermissionsList(req));
        }

        public msgGenericItemList<msgPermissionInfo> GetMemberInheritedPermissionsList(msgGenericItemRequest<int> req)
        {
            return new msgGenericItemList<msgPermissionInfo>(Tools.GetMemberInheritedPermissionsList(req));
        }

        public msgGenericItemResponse<int> UpdateMemberPermissions(msgMemberPermissionInfo req)
        {
            return new msgGenericItemResponse<int>(Tools.UpdateMemberPermissions(req));
        }

        #endregion


    }
}
